package com.asiainfo.wx.portal;

import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Copyright: Copyright (c) 2019  zteits
 *
 * @ClassName: com.asiainfo.wx.portal
 * @Description:
 * @version: v1.0.0
 * @author: atao
 * @date: 2019-11-04   22:16
 * Modification History:
 * Date         Author          Version      Description
 * ---------------------------------------------------------*
 * 2019-11-04      atao          v1.0.0          创建
 */
@Controller
@RequestMapping("/wx/busi")
@Slf4j
public class WxBusiController {

    @Autowired
    private WxMpService wxService;

    /**
     * 展示充值话费页面
     * @param
     * @return
     * @Author: atao
     * @Date: 2019-11-05 18:41
     *
     */
    @GetMapping("/phoneRechargePage")
    public String phoneRechargePage(@RequestParam("code") String code,
        @RequestParam(value = "state", required = false) String state)
        throws WxErrorException {

        WxMpOAuth2AccessToken accessToken = wxService.oauth2getAccessToken(code);
        log.info("获取用户授权信息为:state={},accessToken={}", state, JSONObject.toJSONString(accessToken));
        return "deposit/index";
    }

    /**
     * 展示用户绑定页面
     * @param
     * @return
     * @Author: atao
     * @Date: 2019-11-05 18:41
     *
     */
    @GetMapping("/userBindPage")
    public String userBind(@RequestParam("code") String code,
        @RequestParam(value = "state", required = false) String state)
        throws WxErrorException {

        WxMpOAuth2AccessToken accessToken = wxService.oauth2getAccessToken(code);
        log.info("获取用户授权信息为:state={},accessToken={}", state, JSONObject.toJSONString(accessToken));
        return "phone-trans/phone-bind";
    }

    /**
     * 展示用户解绑页面
     * @param
     * @return
     * @Author: atao
     * @Date: 2019-11-05 18:41
     *
     */
    @GetMapping("/userUnbindPage")
    public String userUnbind(@RequestParam("code") String code,
        @RequestParam(value = "state", required = false) String state)
        throws WxErrorException {

        WxMpOAuth2AccessToken accessToken = wxService.oauth2getAccessToken(code);
        log.info("获取用户授权信息为:state={},accessToken={}", state, JSONObject.toJSONString(accessToken));
        return "phone-trans/phone-unbind";
    }

    /**
     * 展示返档预约页面
     * @param
     * @return
     * @Author: atao
     * @Date: 2019-11-05 18:42
     *
     */
    @GetMapping("/custInfoOrderPage")
    public String custInfoOrderPage(@RequestParam("code") String code,
        @RequestParam(value = "state", required = false) String state)
        throws WxErrorException {

        WxMpOAuth2AccessToken accessToken = wxService.oauth2getAccessToken(code);
        log.info("获取用户授权信息为:state={},accessToken={}", state, JSONObject.toJSONString(accessToken));
        return "phone-order/index";
    }

    /**
     * 展示自助返档页面
     * @param
     * @return
     * @Author: atao
     * @Date: 2019-11-05 18:42
     *
     */
    @GetMapping("/custInfoHandelPage")
    public String custInfoHandelPage(@RequestParam("code") String code,
        @RequestParam(value = "state", required = false) String state)
        throws WxErrorException {

        WxMpOAuth2AccessToken accessToken = wxService.oauth2getAccessToken(code);
        log.info("获取用户授权信息为:state={},accessToken={}", state, JSONObject.toJSONString(accessToken));
        return "self-return/index";
    }

    /**
     * 展示号码过户页面
     * @param
     * @return
     * @Author: atao
     * @Date: 2019-11-05 18:42
     *
     */
    @GetMapping("/phoneNumTransferPage")
    public String phoneNumTransferPage(@RequestParam("code") String code,
        @RequestParam(value = "state", required = false) String state)
        throws WxErrorException {

        WxMpOAuth2AccessToken accessToken = wxService.oauth2getAccessToken(code);
        log.info("获取用户授权信息为:state={},accessToken={}", state, JSONObject.toJSONString(accessToken));
        return "ownership-trans/index";
    }

}
